$(window).ready(function() {
	$("#studentDialog").dialog($.extend({}, $.ui.dialogDefaultConfig, {
		modal : true,
		resizable : true,
		minHeight : 300,
		minWidth : 100,
		width : 560,
		height : 360,
		autoOpen : false,
		buttons : [ {
			"text" : i18n.global.close,
			"click" : function() {
				$(this).dialog("close");
			}
		} ]
	}));
	$("#subjectDialog").dialog($.extend({}, $.ui.dialogDefaultConfig, {
		modal : true,
		resizable : true,
		minHeight : 300,
		minWidth : 100,
		width : 560,
		height : 360,
		autoOpen : false,
		buttons : [ {
			"text" : i18n.global.close,
			"click" : function() {
				$(this).dialog("close");
			}
		} ]
	}));
	initClickEvent();
});

/**
 * 处理树点击操作
 */
function zTreeOnClick(event, treeId, treeNode) {
	if (treeNode.queryObjectName == "com.wef.demo.entity.Student") {
		$("#studentDialog").dialog("open");
		FormUtils.convertSimpleObject2Form(treeNode.targetObject,
				"searchFormStudent");
	}

	else {
		$("#subjectDialog").dialog("open");
		FormUtils.convertSimpleObject2Form(treeNode.targetObject,
				"searchFormStudentSubject");
	}

};
/**
 * 处理下拉树点击操作
 */
function stuNameIdTreeClick(event, treeId, treeNode) {
	var elm = $('#studentNameId');
	elm.val(treeNode.targetObject.studentName);
};
/**
 * 处理保存操作
 */
function initClickEvent() {
	$('#saveBtnStudentSubject').bind(
			'click',
			function() {
				var dwrOption = {
					callback : function(result) {
						var treeObj = $.fn.zTree.getZTreeObj("divTree");
						alert("save ok");
						treeObj.reAsyncChildNodes(null, "refresh");
					}
				};
				StudentSubjectService.updateStudentSubject(FormUtils
						.convertSimpleForm2Object("searchFormStudentSubject",
								null), $.DwrUtils.proDwrOption(dwrOption));
			});

	$('#saveBtnStudent').bind(
			'click',
			function() {
				var dwrOption = {
					callback : function(result) {
						var treeObj = $.fn.zTree.getZTreeObj("divTree");
						alert("save ok");
						FormUtils.convertSimpleObject2Form(result,
								"searchFormStudent");
						treeObj.reAsyncChildNodes(null, "refresh");
					}
				};
				StudentService.updateStudent(FormUtils.convertSimpleForm2Object("searchFormStudent", null), $.DwrUtils.proDwrOption(dwrOption));
			});

};